#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  freopen("scramble.in", "r", stdin);
  freopen("scramble.out", "w", stdout);
  int n;

  cin >> n;
  vector<pair<string, int>> min_str(n), max_str(n);

  for (int i = 0; i < n; i++) {
    cin >> min_str[i].first;

    min_str[i].second = i;
    sort(min_str[i].first.begin(), min_str[i].first.end());
    max_str[i] = min_str[i];
    reverse(max_str[i].first.begin(), max_str[i].first.end());
  }
  sort(min_str.begin(), min_str.end());
  sort(max_str.begin(), max_str.end());

  vector<pair<int, int>> ans(n);

  {
    for (int i = 0, j = 0; i < n; i++) {
      while (j < n) {
        if (max_str[j].first < min_str[i].first) {
          j++;
        } else {
          break;
        }
      }
      ans[min_str[i].second].first = j + 1;
    }
  }

  {
    for (int i = 0, j = 0; i < n; i++) {
      while (j < n) {
        if (min_str[j].first <= max_str[i].first) {
          j++;
        } else {
          break;
        }
      }
      ans[max_str[i].second].second = j;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}